package com.bluefox.condition;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Author : 孙峰
 * @Description: 判断是否是Windows系统
 * @Date : 2021/8/31  17:19
 */
@Slf4j
public class WindowsCondition implements Condition {
    /**
     * @param conditionContext      判断条件能使用的上下文环境
     * @param annotatedTypeMetadata 注释信息
     * @return
     */
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {

        // 3、获取当前环境信息
        Environment environment = conditionContext.getEnvironment();

        String property = environment.getProperty("os.name");
        assert property != null;
        return property.toLowerCase().contains("windows");
    }
}
